<div class="content last ui-widget-content">
	<div class="content-full">
		<div style="width: 98%;padding-left: 5px;">
			<?php if (count($this->arrError)>0) echo $this->error($this->arrError); ?>
			<div id="create-question">
			<div class="cms_table">
					<h2>Loại câu hỏi : <?php echo $this->nameTypeQuestion; ?></h2>
					<form action="<?php echo BASE_URL; ?>/question/<?php echo $this->action;?>"	method="POST" name="question-form" id="question-form">
						<input type="hidden" name="type" id="type" value="<?php echo $this->ObjQuestion['type'];?>">
						<input type="hidden" name="id" value="<?php echo $this->ObjQuestion['id'] ;?>">		
						<input type="hidden" name="isupdate" value="<?php echo $this->ObjQuestion['isupdate'];?>"/>
						<input type="hidden" name="created_user" value="<?php echo $this->ObjQuestion['created_user'];?>"/>			
						<table cellpadding="0" cellspacing="0">
							<tr><td class="label">
									Chọn môn học: 
									</td><td class="field_container"><?php echo $this->SltSubject("subject_id", $this->ObjQuestion['subject_id'],$this->arrSubjectId); ?>
							</td></tr>
							<tr><td class="label">
									Chọn chương môn học:
									</td><td class="field_container">
									<span class="chapter_id">
										<?php echo $this->SltChapterSubject("chapter_id", $this->ObjQuestion['chapter_id'], $this->ObjQuestion['subject_id']); ?>
									</span><p class="chapterSubject_description"></p>
							</td></tr>
							<tr><td class="label">
										Tiêu đề câu hỏi:  
								</td><td class="field_container">
								<textarea style="font-size: 16px;font-weight: 600;" name="question_title" rows="3" cols="20"><?php echo $this->ObjQuestion['question_title'];?></textarea>
							</td></tr>
							<tr><td colspan="3">
								<p>
									 <label><b> Nội dung câu hỏi:</b> </label><br/>
									<textarea id="question-editor" class="question-editor" name="content" rows="8" cols="20"><?php echo $this->ObjQuestion['content']; ?></textarea>
								</p>
							</td></tr>
							<tr><td colspan="3">
									<p>
										<label><b> Giải thích cho câu trả lời:</b> </label><br />
										<textarea class="editor" id="generalfeedback" name="generalfeedback" rows="3" cols="20"><?php echo $this->ObjQuestion['generalfeedback'];?></textarea>
									</p>
							</td></tr>
							<tr><td class="label">
										Độ khó:
										</td><td class="field_container">
										<?php echo $this->SltLevel("level",$this->ObjQuestion['level']); ?>
							</td></tr>
							<tr><td class="label">
										Độ phân cách:
										</td><td class="field_container">
										<?php echo $this->SltClassification("classification",$this->ObjQuestion['classification']); ?>
							</td></tr>
							<tr><td class="label">
										Điểm mặc định cho câu hỏi:
										</td><td class="field_container"><input onchange="validateNum(this); return false;" type="text" name="score" value="<?php  echo $this->ObjQuestion['score']; ?>" >
							</td></tr>
							<tr><td class="label">
										Một hay nhiều phương án đúng:
									</td><td class="field_container">
										<?php echo $this->sltOneOrMoreTrue("oneormoretrue", $this->ObjQuestion['oneormoretrue']); ?>
							</td></tr>
							<!--  đoạn này chưa cần, có thể edit về sau nếu có yêu cầu như thế xảy ra 
							<tr><td class="label">
									<p>
										<label>Xáo trộn các phương án trả lời
										</td><td class="field_container"><input type="checkbox" name="shuffle" <?php // if($this->ObjQuestion['shuffle']=='on') echo "checked"; ?> >
									</p>
							</td></tr>
							
							<tr><td class="label">
									<p>
										<label>Đánh số các phương án trả lời
										</td><td class="field_container">
										<?php // echo $this->sltAnswerNumbering("displayanswer", $this->ObjQuestion['displayanswer']); ?>
									</p>
							</td></tr>
							 -->
							 
							<?php if( $this->ObjQuestion['isupdate'] == 1){ ?>
							<tr><td class="label">
										Ngày tạo:
										</td><td class="field_container"><input type="text" name="timecreated" size="40" readonly="readonly" value="<?php  echo Zend_View_Helper_FormatDate::convertYmdToMdy($this->ObjQuestion['timecreated']); ?>" >
							</td></tr>
							<tr><td class="label">
										Ngày chỉnh sửa gần nhất:
										</td><td class="field_container"><input type="text" name="timemodified" size="40" readonly="readonly" value="<?php  echo Zend_View_Helper_FormatDate::convertYmdToMdy($this->ObjQuestion['timemodified']); ?>" >
							</td></tr>
							<?php } ?>						
							<tr><td class="label">
										Không cho sinh viên thực hành câu này: 
										</td><td class="field_container"><input type="checkbox" name="hidden" <?php if($this->ObjQuestion['hidden']=='on') echo "checked"; ?> >
							</td></tr>
							<tr><td colspan="5"  style="background-color: #4E8EDF; font-size: 15px; color: white; font-family: tahoma;"  >
									<p align="center">
										<label class="title-info-ans-question">ĐIỀN THÔNG TIN CHO CÁC CÂU TRẢ LỜI
										</label>  
									</p>
							</td></tr>
							
							</table>		
						<?php if(count($this->ObjQuestion['ans'])==0){?>			
							<div class="answer-box ui-state-default">
								<table style="border: 3px solid orange">
								<tr><td>
										<p>
											<label>Điểm cho câu trả lời này &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
											</label> <?php echo $this->sltPerScore("perscore[]", 0); ?>
										</p>
								</td></tr>
									<tr>
										<td style="text-align: right;">
											<input type="hidden" name="ansID[]" value=""> 
											<span id="delete_ans_0" class="delete-answer-icon" onclick="bindAnswerDelete($(this).attr('id'));"> <b><font color="red">Xóa câu trả lời</font></b> 
											<img class="fugue fugue-cross-circle" alt=""	src="<?php echo BASE_URL; ?>/img/icons/space.gif" />
											</span> 
										</td>
									</tr>
									<tr>
										<td colspan="2">
											<textarea id="ans_0" class="editor" name="ans[]" cols="20" rows="2"></textarea>												
										</td>
									</tr>
									<tr>
										<td colspan="2">
											<label>Phản hồi cho câu trả lời</label>
											<textarea  name="feedback[]" rows="3" cols="20"></textarea>
										</td>
									</tr>								
								</table>  
								
							</div>					
							<div class="answer-box ui-state-default">
								<table style="border: 3px solid orange">
									<tr><td >
											<p>
												<label>Điểm cho câu trả lời này &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
												</label> <?php echo $this->sltPerScore("perscore[]", 0); ?>
											</p>
									</td></tr>
									<tr>
										<td style="text-align: right;">
											<input type="hidden" name="ansID[]" value=""> 									
											<span id="delete_ans_1" class="delete-answer-icon" onclick="bindAnswerDelete($(this).attr('id'));"> <b><font color="red">Xóa câu trả lời</font></b> 
											<img class="fugue fugue-cross-circle" alt=""	src="<?php echo BASE_URL; ?>/img/icons/space.gif" />
											</span> 
										</td>
									</tr>
									<tr>
										<td colspan="2">
											<textarea id="ans_1" class="editor" name="ans[]" cols="20" rows="2"></textarea>												
										</td>
									</tr>
									<tr>
										<td colspan="2">
											<label>Phản hồi cho câu trả lời</label>
											<textarea  name="feedback[]" rows="3" cols="20"></textarea>
										</td>
									</tr>								
								</table>  
							</div>
						<?php }else { ?>
							<?php foreach ($this->ObjQuestion['ans'] as $key=>$itemAns){
								$ans_id       = $this->ObjQuestion['ansID'][$key];
								//$order      = $this->ObjQuestion['order'][$key];
								$perscore     = $this->ObjQuestion['perscore'][$key];
								$feedback     = $this->ObjQuestion['feedback'][$key];
								$ans_content  = $this->ObjQuestion['ans'][$key];
							?>
									<div class="answer-box ui-state-default">
										<table style="border: 3px solid orange">
											<tr><td>
													<p>
														<label>Điểm cho câu trả lời này &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
														</label> <?php echo $this->sltPerScore("perscore[]", $perscore); ?>
													</p>
											</td></tr>
											<tr>
												<td style="text-align: right;">
													<input type="hidden" name="ansID[]" value="<?php echo $ans_id; ?>"> 									
													<span id="delete_ans_<?php echo $key; ?>" class="delete-answer-icon" onclick="bindAnswerDelete($(this).attr('id'));"> <b><font color="red">Xóa câu trả lời</font></b> 
													<img class="fugue fugue-cross-circle" alt=""	src="<?php echo BASE_URL; ?>/img/icons/space.gif" />
													</span> 
												</td>
											</tr>
											<tr>
												<td colspan="2">
													<textarea id="ans_<?php echo $key; ?>" class="editor" name="ans[]" cols="20" rows=""><?php echo $ans_content;?></textarea>												
												</td>
											</tr>
											<tr>
												<td colspan="2">
													<label>Phản hồi cho câu trả lời</label>
													<textarea  name="feedback[]" rows="3" cols="20"><?php echo $feedback;?></textarea>
												</td>
											</tr>
										</table>  									
									</div>
								<?php } ?>
						<?php } ?>
						<p align="center">
							<br/>
							<span class="add-answer-icon ui-state-default ui-corner-top" style="padding: 5px;"> <b><font color="green" size="4">Thêm câu trả lời</font></b> 
								<img class="fugue fugue-plus-circle" alt=""	src="<?php echo BASE_URL; ?>/img/icons/space.gif" /> 
							</span>
						</p>	
							<table style="width: 200px;margin: auto;">
								<tr>
									<td style="vertical-align: top;text-align: left;">
										<input type="submit" class="button add-answer-icon ui-corner-all ui-state-default"  value="Đồng ý">
									</td>
									<?php if($this->ObjQuestion['isupdate']==1){ ?>
									<td style="vertical-align: top;text-align: left;">
										<input type="button" onclick="window.close()" value="Hủy bỏ" class="button add-answer-icon ui-corner-all ui-state-default"> 
									</td>
									<?php } else { ?>
									<td style="vertical-align: top;text-align: left;">
										<input  type="button" value="Hủy bỏ" onclick="window.location='<?php echo  BASE_URL.'/question';  ?>'" style="font-size: 15px;" class="add-answer-icon ui-state-default ui-corner-all"> 
									</td>
									<?php }  ?>
								</tr>
							</table>
	
					</form>
				</div>
				<!-- xử lý show perscore lúc thêm 1 câu trả lời. 
					 1. vì trong xử lý js ta cần phải insert 1 đoạn HTML để đc 1 view của 1 answer mới tạo
					 2. do trong file js ko thể thực thi lệnh php -> tạo trước view của sltPerscore() và để ần vào đây
					 3. gọi xử lý trong js chỉ lấy nội dung html (line: 24)					
				 -->
				<div style="display: none;" id="sltPerscoreHidden">
					<?php echo $this->sltPerScore("perscore[]", 0); ?>
				</div>
			</div>
		</div>
	</div>
</div>


<script type="text/javascript">
$(document).ready(function(){			
			$("#subject_id").change(function(){			
			var subject_id = $("#subject_id").val();
			 $.ajax({
			   type: "POST",
			   url: $("#BASE_URL").val()+"/chaptersubject/ajaxgetchaptersubject"+"/token/"+fnGenToken(),
			   data: "subject_id="+subject_id,
			   dataType: "json",
			   success: function(data){
					if(data['success']==true){
								$(".chapter_id").html(data['sltChapterSubject']);
    						 }
    						 else
    							 alert("Có lỗi: "+data['error']); 
    				}			      
			 });
			 
		});
});			
</script>

